import { defineStore, createPinia } from "pinia";
import piniaPersistConfig from "@/@CORE/app-config/piniaPersist";
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";

export const GlobalStore = defineStore({
	id: "GlobalState",
	state: () => ({
		// 签名信息
		token: "",
		// 用户信息
		userInfo: {},
		// 当前激活的菜单
		activeMenu: undefined
	}),
	actions: {
		SET_TOKEN(token) {
			this.token = token;
		},
		SET_USERINFO(userInfo) {
			this.userInfo = userInfo;
		},
		SET_ACTIVEMENU(activeMenu) {
			this.activeMenu = activeMenu;
		}
	},
	persist: piniaPersistConfig("GlobalState", { include: ["token", "userInfo", "activeMenu"] })
});

const pinia = createPinia();
pinia.use(piniaPluginPersistedstate);

export default pinia;
